package au.edu.swin.swinvehicle.vehicletype;

/**
 * VehicleType entity
 * @version 1.0
 * @author Viet Bui, Dany Gunawan
 * @lastmodify 2009-05-11 (Dany Gunawan)
 */
import au.edu.swin.swinvehicle.vehicle.VehicleEntity;
import au.edu.swin.swinvehicle.vehiclebooking.VehicleBookingEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@NamedQueries({
    @NamedQuery(name = "findAllVehicleTypes",
    query = "SELECT vt FROM VehicleTypeEntity vt WHERE vt.deleted = false")
})
@Table(name = "VEHICLETYPE")
public class VehicleTypeEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(length = 15, nullable = false)
    private String code;
    @Column(length = 63, nullable = false)
    private String description;
    @Column(nullable = false)
    private Integer seats;
    @Column(name = "DELETED")
    private Boolean deleted;
    @OneToMany(mappedBy = "vehicleType", cascade = CascadeType.ALL)
    private List<VehicleEntity> vehicles;
    @OneToMany(mappedBy = "vehicleType", cascade = CascadeType.ALL)
    private List<VehicleBookingEntity> vehicleBookings;

    /**
     * Default constructor
     */
    public VehicleTypeEntity() {
        vehicles = new ArrayList<VehicleEntity>();
    }

    public VehicleTypeEntity(String code, String description, Integer seats, Boolean deleted) {
        this(); // Call default constuctor
        setCode(code);
        setDescription(description);
        setSeats(seats);
        setDeleted(deleted);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getSeats() {
        return seats;
    }

    public void setSeats(Integer seats) {
        this.seats = seats;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public List<VehicleEntity> getVehicles() {
        return vehicles;
    }

    public void setVehicles(List<VehicleEntity> vehicles) {
        this.vehicles = vehicles;
    }

    // Transfer object methods
    public VehicleTypeTO getData() {
        return new VehicleTypeTO(id, code);
    }

    public VehicleTypeDetailedTO getDetailedData() {
        return new VehicleTypeDetailedTO(id, code, description, seats, deleted);
    }

    // Only the VehicleTypeDetailedTO can be used to update the state of the vehicle entity
    public void setData(VehicleTypeDetailedTO to) {
        setId(to.getId());
        setCode(to.getCode());
        setDescription(to.getDescription());
        setSeats(to.getSeats());
        setDeleted(to.getDeleted());
    }

    public List<VehicleBookingEntity> getVehicleBookings() {
        return vehicleBookings;
    }

    public void setVehicleBookings(List<VehicleBookingEntity> vehicleBookings) {
        this.vehicleBookings = vehicleBookings;
    }

    // Not doing mergeData() at the moment.
    @Override
    public String toString() {
        return "au.edu.swin.swinvehicle.vehicletype.VehicleTypeEntity[id=" + id + "]";
    }
}
